import requests, unittest
from ddt import ddt, file_data

@ddt
class create(unittest.TestCase):
    def setUp(self) -> None:
        print('start case')

    def tearDown(self) -> None:
        print('end case')

    token=None
    def test_01_login(self):
        url = 'http://10.59.9.14:7003/api/public/login'
        data = {"username": '18185603008', "password": '123456'}
        login = requests.post(url=url, json=data)
        print(login.json())
        create.token = login.json()['data']['token']
        print(create.token)

    @file_data('data.yaml')
    def test_02_create(self,spid,address_id):
        url = 'http://10.59.9.14:7003/api/order/create'
        headers = {'auth-token':'Bearer ' + create.token}
        data = {"id":spid,"type":"buy","address_id":address_id,"store_id":1,"shipping_type":1,"bonus_id":"0","payment":"balance","remarks":"","source":1,"url":"http://10.59.9.14:7003/wap/pages/cart/confirm?id=71&sku_id=&num=1&type=buy","sku_id":"","num":"1"}
        chuanjian  = requests.post(url=url,headers=headers, json=data)
        print(chuanjian.json())


if __name__ == '__main__':
    # unittest.main()
    # suite = unittest.TestSuite()
    # suite.addTest(create('test_01_login'))
    # suite.addTest(create('test_02_create'))
    # runner = unittest.TextTestRunner()
    suite = unittest.defaultTestLoader.discover(start_dir='/', pattern='rk_crear.py')
    runner = unittest.TextTestRunner()
    runner.run(suite)